package com.ruc.deke.controller;

import java.util.ArrayList;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ruc.deke.dao.DBCourseDAO;
import com.ruc.deke.dao.TeacherDAO;
import com.ruc.deke.dao.UserDAO;
import com.ruc.deke.model.DBRecord;
import com.ruc.deke.model.Teacher;
import com.ruc.deke.model.User;
import com.ruc.deke.utils.NotificationUtil;
import com.ruc.deke.utils.ParseUtil;

/**
 * 后台管理，用于进行教师、学生账号等的管理
 * 
 * @author: cyj
 * @date: 2017年8月31日 下午10:32:33
 */

@Controller
@RequestMapping(value = "/manager")
public class ManagerController {

	@Resource(name = "userDAOImpl")
	private UserDAO userDAO;

	@Resource(name = "teacherDAOImpl")
	private TeacherDAO teacherDAO;

	@Resource(name = "dbCourseDAOImpl")
	private DBCourseDAO dbCourseDAO;

	/**
	 * 添加学校
	 */
	// @RequestMapping(value="/addUni",method=RequestMethod.POST)
	// @ResponseBody
	// public Object register(University uni){
	// return null;
	// }
	//

	/**
	 * 添加一个教师账号
	 * 
	 * @param teacher
	 * @return
	 * @author: cyj
	 * @date: 2017年8月31日 下午10:37:28
	 */
	@RequestMapping(value = "/addTeacher", method = RequestMethod.POST)
	@ResponseBody
	public Object register(Teacher teacher) {
		boolean isSucc = teacherDAO.addTeacher(teacher);
		return isSucc ? ParseUtil.toObject("success") : ParseUtil.toObject("failed");
	}

	/**
	 * 获取已经提交的人
	 * 
	 * @param session
	 * @param moduleId
	 * @return
	 * @author: cyj
	 * @date: 2017年4月4日 上午11:19:08
	 */
	@RequestMapping(value = "/haveSubmitedByAnoAndModule")
	@ResponseBody
	public ArrayList<DBRecord> haveSubmitedByAnoAndModule(HttpSession session, int moduleId) {
		String ano = session.getAttribute("ano").toString();//////
		ArrayList<DBRecord> records = new ArrayList<DBRecord>();
		records = userDAO.haveSubmitedByAnoAndModule(moduleId, ano);
		return records;
	}

	/**
	 * 删除某userid的答题记录
	 * 
	 * @author gyh_f
	 * 
	 */

	@RequestMapping(value = "/deleteUserRec")
	@ResponseBody
	public Boolean deleteUserRec(int userId) {
		// int userId = 111;
		Boolean state = userDAO.deleteRec(userId);
		return state;
	}

}
